#include "searcher.h"
#include "ui_searcher.h"

searcher::searcher(QWidget *parent) :
    QDialog(parent),
    selMainWidget(nullptr),
    ui(new Ui::searcher)
{
    search_current_form = nullptr;
    search_all_form = nullptr;
    ui->setupUi(this);
    origin_x = parent->x() + (parent->width()/3);
    origin_y = parent->y() + (parent->height()/3);
    InitUI();
}

searcher::~searcher()
{
    delete ui;
}

void searcher::keyPressEvent(QKeyEvent *e)
{
    is_key_event_emit(e);
    QWidget::keyPressEvent(e);
}

void searcher::showEvent(QShowEvent *e)
{
    if(selMainWidget){
        selMainWidget->show();
    }
}

void searcher::InitUI()
{
    selMainWidget = new WidgetPar;
    selMainWidget->addWidget(this);
    this->installEventFilter(selMainWidget);
    selMainWidget->setWindowIcon(":/images/search.png");
//    QGridLayout * pLayout = new QGridLayout();
//    pLayout->addWidget(titlebar);
//    pLayout->addWidget(this);
//    pLayout->setSpacing(0);
//    pLayout->setContentsMargins(0,0,0,0);
//    selMainWidget->setLayout(pLayout);
//    selMainWidget->setAttribute(Qt::WA_TranslucentBackground, true);
//    selMainWidget->setSizePolicy(this->sizePolicy());
//    selMainWidget->setMaximumSize(this->maximumSize());
//    this->setWindowTitle("88888");
//    selMainWidget->move(origin_x,origin_y);
//    selMainWidget->resize(500,500);
    ui->tabWidget->removeTab(0);
    ui->tabWidget->removeTab(0);
    search_current_form = new QWidget(this);
    search_all_form = new QWidget(this);
    if(editer_bar::get_current_file().length()){
        ui->tabWidget->addTab(search_current_form, tr("查找当前文件"));
    }
        ui->tabWidget->addTab(search_all_form, tr("查找知识库"));
}

void searcher::show()
{
    if(selMainWidget){
         selMainWidget->show();
         QWidget::show();
    }
}

void searcher::hide()
{
    if(selMainWidget){
         selMainWidget->hide();
         QWidget::hide();
    }
}


